package com.charles.seckillGateway.config;

import com.charles.seckillGateway.handler.ValidateCodeHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.server.RequestPredicates;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;

import javax.annotation.Resource;

/**
 * @author Charles-H
 * 
 * 配置路由，拦截 '/code'路径
 */
@Configuration
public class RouterFunctionConfig {
    
    @Resource
    private ValidateCodeHandler validateCodeHandler;

    @SuppressWarnings("rewtypes")
    @Bean
    public RouterFunction routerFunction() {
        return RouterFunctions.route(
                RequestPredicates.GET("/code")
                .and(RequestPredicates.accept(MediaType.TEXT_PLAIN)), validateCodeHandler
        );
    }
    
}
